export * from './getToolButtonList';
export * from './getUrlParms';
export * from './action';
import * as Fiber from 'fiber';

//判断插件
export const hasPlugin = (name) => {
  return name && window._plugins.indexOf(name) !== -1;
};
export const showDetailPage = function (url, id) {
  if (!url.includes("edoc") && !url.includes("govdoc")) {
    url += "&showTab=true";
  }
  let param = { url };
  if (id) {
    param.id = id;
  }
  const a8Top = getA8Top();
  if (a8Top.isMultipleTabs && url.includes("showTab=true") && !isOcipSummary(url, id)) {
    a8Top.openCtpWindow(param);
  } else {
    openCtpWindow(param);
  }
};
//ocip推送过来的数据，不走多页签
function isOcipSummary(url, id) {
  if ($.ctx.hasPlugin("ocip") && url.includes("method=summary&") && url.includes("showTab=true") && url.includes('affairId')) {
    return callBackendMethod("ocipColManager", "checkIsExchangeAffair", id);
  } else {
    return false;
  }
}
export const initV3x = function () {
  let _v3x;
  Object.defineProperty(window, 'v3x', {
    get() {
      if (!_v3x) {
        _v3x = new V3X();
        _v3x.init(window._ctxPath, window._locale);
      }
      return _v3x;
    },
    set(value) {
      _v3x = value;
    }
  });
};

export const getDefaultValueSearchCondition = function(conditions) {
  const result = {};
  conditions.forEach(element => {
    if (element.defaultValue && element.defaultValue.value) {// 解析默认值
      if (element.type == 'SELECT_WORKFLOW_TEMPLATE_RADIO') {// 带单选按钮的模板选择控件
        result[element.key] = element.defaultValue.value;
        result[element.key+'Ids'] = element.defaultValue.templateValue;
      } else {
        result[element.key] = element.defaultValue.value;
      }
    }
  });

  return result;
}

export const loadComponentsThemeDefaultCSS = function(url) {
  if (url || (window._ctxPath && window._ctpSkinUrl)) {
    const cssFile = document.createElement('link');
    cssFile.rel = 'stylesheet';
    cssFile.href = url ? url : window._ctxPath + window._ctpSkinUrl;
    document.getElementsByTagName('head')[0].appendChild(cssFile);
  }
}

export function toastForward(result){
  if (result && result instanceof Array && result.length > 0) {
    Fiber.modal.warning({
      title: $.i18n('common.system.hint.label'),
      content:(h)=> <div>{$.i18n('collaboration.grid.alert.thisSelectNotForward')}
        {result.map(showTitle=><p style="margin:0" domPropsInnerHTML={showTitle} ></p>)}
      </div>,
    });
  }
  
}
